import React from 'react'
import './index.scss'
export default function MyCount({ goods_count, changeCount }) {
  const increment = () => {
    // !#3 孙子调用方法的同时并传参：id、期望数值
    changeCount(goods_count + 1)
  }
  const decrement = () => {
    let gc = goods_count - 1
    if (gc <= 1) {
      gc = 1
    }
    changeCount(gc)
  }
  return (
    <div className='my-counter'>
      <button type='button' className='btn btn-light' onClick={decrement}>
        -
      </button>
      <input
        type='number'
        className='form-control inp'
        value={goods_count}
        onChange={() => {}}
      />
      <button type='button' className='btn btn-light' onClick={increment}>
        +
      </button>
    </div>
  )
}
